package com.example.image.glidemodule

import android.content.Context
import com.bumptech.glide.GlideBuilder
import com.bumptech.glide.annotation.GlideModule
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory
import com.bumptech.glide.load.engine.cache.LruResourceCache
import com.bumptech.glide.load.engine.cache.MemorySizeCalculator
import com.bumptech.glide.module.AppGlideModule

/**
 * 自定义Glide缓存大小
 */
@GlideModule
class GlideModule:AppGlideModule() {
    override fun applyOptions(context: Context, builder: GlideBuilder) {
        //修改内存缓存大小              默认缓存大小为当前app的1/8  现在设置1/6
        val cacheSize = MemorySizeCalculator.Builder(context).build().memoryCacheSize/6L
        builder.setMemoryCache(LruResourceCache(cacheSize))
        //设置磁盘缓存大小               默认250mb   现在设置300mb
        builder.setDiskCache(InternalCacheDiskCacheFactory(context,"glideDiskCache",1024*1024L*300))
        //
    }
}